<?php

namespace App\Http\ManagerApi\Controllers;

use App\Api\BaseClass\Controller;
use Illuminate\Support\Facades\Crypt;
use App\Http\ManagerApi\Models\PlatformSetting;




class ParamsController extends Controller
{

    public function setParams()
    {

        $rules = [
            // 注册费,报单金额
            ['register_fee', 'required|integer'],
            // 平台注册手续费比例
            ['service_charge_rate', 'required|numeric'],
            // 佣金比例
            ['commission_rate', 'required|numeric'],
            // 直属下级获取上级返利最小推荐人数
            ['sub_max_number', 'required|integer'],
            // 直属下级获取上级返利比例
            ['sub_rebate_rate', 'required|numeric'],
            // 激活密码
            ['activation_cipher','required|string']
        ];

        $params = $this->form->camelFormOrFail($rules);
        $params['activation_cipher'] = Crypt::encryptString($params['activation_cipher']);

        $data = PlatformSetting::first();
        if(!isset($data)){
            $data = new PlatformSetting();
        }
        return $this->form->updateMessage($data->fill($params)->save());
    }

    public function getParams(){
        return $this->form->datas(PlatformSetting::first());
    }
}